﻿<UserControl x:Class="EraDeiFessi.Controls.LinkUnblocker" x:Name="lu1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:myControls="clr-namespace:EraDeiFessi.Controls"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600">
    <UserControl.Resources>
        <BooleanToVisibilityConverter x:Key="bool2vis"/>
    </UserControl.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Grid Grid.RowSpan="3" Grid.Row="2" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Panel.ZIndex="999" Background="#ddffffff" x:Name="gridUUnblocking" Visibility="Hidden">
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2 -60 2 2" Orientation="Horizontal">
                <myControls:LoadingPanel VerticalAlignment="Center" Margin="2" Loaded="LoadingPanel_Loaded"/>
                <TextBlock FontWeight="Bold" FontSize="16" VerticalAlignment="Center" Margin="2">Sblocco dei link in corso - (</TextBlock>
                <TextBlock FontWeight="Bold" FontSize="16" VerticalAlignment="Center" Margin="2" Text="{Binding ElementName=lu1, Path=UnblockProgress}"/>
                <TextBlock FontWeight="Bold" FontSize="16" VerticalAlignment="Center" Margin="2"> di </TextBlock>
                <TextBlock FontWeight="Bold" FontSize="16" VerticalAlignment="Center" Margin="2" x:Name="tbTotal"></TextBlock>
                <TextBlock FontWeight="Bold" FontSize="16" VerticalAlignment="Center" Margin="2">)</TextBlock>
            </StackPanel>

            <ProgressBar HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="25" Margin="40 2 40 2" x:Name="pbUnblock" Value="{Binding ElementName=lu1, Path=UnblockProgress}"/>
        </Grid>

        <GroupBox Margin="2" Header="Link da sbloccare" Grid.ColumnSpan="2">
            <TextBox AcceptsReturn="True" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" x:Name="txtLinks" TextChanged="txtLinks_TextChanged"></TextBox>
        </GroupBox>

        <Button Margin="2" Content="Sblocca tutti i link" Grid.Row="1" Grid.ColumnSpan="2" Width="200" Height="30" x:Name="buttonUnblock" Click="btnUnblock_Click" IsEnabled="{Binding ElementName=lu1, Path=CanUnblock}"/>

        <GroupBox Margin="2" Header="Link sbloccati" Grid.Row="2">
            <ListView ItemsSource="{Binding ElementName=lu1, Path=UnblockedLinks}" SelectionMode="Extended" SelectionChanged="listUnblocked_SelectionChanged" x:Name="listUnblocked">
                <ListView.ItemTemplate>
                    <DataTemplate>

                        <Grid HorizontalAlignment="Stretch">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>

                            <StackPanel x:Name="stackLinkOk" Orientation="Vertical" Margin="0">
                                <TextBlock Margin="2" FontWeight="Bold" FontSize="12" Text="{Binding FileName}"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Margin="2" FontWeight="Normal" Foreground="Gray" FontSize="10" Text="{Binding FileSize}"/>
                                    <TextBlock Margin="2" FontWeight="Normal" Foreground="Gray" FontSize="10" Text=" - "/>
                                    <TextBlock Margin="2" FontWeight="Normal" Foreground="Gray" FontSize="10" Text="{Binding FileLink}"/>
                                </StackPanel>

                            </StackPanel>

                            <StackPanel x:Name="stackLinkError" Orientation="Vertical" Margin="0">
                                <TextBlock Margin="2" FontWeight="Bold" FontSize="12" Foreground="Red" Text="ERRORE"/>
                                <TextBlock Margin="2" FontWeight="Normal" Foreground="Gray" FontSize="10" Text="{Binding ErrorMessage}"/>
                            </StackPanel>
                        </Grid>

                        <DataTemplate.Triggers>
                            <DataTrigger Binding="{Binding Path=HasError}" Value="True">
                                <Setter TargetName="stackLinkOk" Property="Visibility" Value="Hidden"/>
                                <Setter TargetName="stackLinkError" Property="Visibility" Value="Visible"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=HasError}" Value="False">
                                <Setter TargetName="stackLinkOk" Property="Visibility" Value="Visible"/>
                                <Setter TargetName="stackLinkError" Property="Visibility" Value="Hidden"/>
                            </DataTrigger>
                        </DataTemplate.Triggers>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </GroupBox>

        <Grid  Grid.Row="2" Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>

            <GroupBox Margin="2" Header="Azioni">
                <StackPanel Orientation="Vertical" Margin="2" VerticalAlignment="Center">
                    <Button Margin="2" Height="28" x:Name="btnRDSelectAll" Click="btnRDSelectAll_Click">
                        <StackPanel Orientation="Horizontal">
                            <myControls:AutoGreyableImage Source="..\Resources\icon_all.png" Margin="2"/>
                            <TextBlock Margin="2" VerticalAlignment="Center">Seleziona tutti</TextBlock>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </GroupBox>

            <GroupBox Margin="2" Header="Link selezionati" Grid.Row="1" VerticalAlignment="Bottom">
                <StackPanel Orientation="Vertical" Margin="2" VerticalAlignment="Center" IsEnabled="{Binding ElementName=lu1, Path=LinksSelected}">

                    <Button Margin="2" Height="28" x:Name="btnRDCopy" Click="btnRDCopy_Click">
                        <StackPanel Orientation="Horizontal">
                            <myControls:AutoGreyableImage Source="..\Resources\icon_clipboard.png" Margin="2"/>
                            <TextBlock Margin="2" VerticalAlignment="Center">Copia</TextBlock>
                        </StackPanel>
                    </Button>
                    <Button Margin="2" Height="28" x:Name="btnRDDownload" Click="btnRDDownload_Click"  IsEnabled="{Binding ElementName=lu1, Path=CanDownload}">
                        <StackPanel Orientation="Horizontal">
                            <myControls:AutoGreyableImage Source="..\Resources\icon_idm.png" Margin="2"/>
                            <TextBlock Margin="2" VerticalAlignment="Center">Scarica (IDM)</TextBlock>
                        </StackPanel>
                    </Button>
                    <Button Margin="2" Height="28" x:Name="btnRDStream" Click="btnRDStream_Click"  IsEnabled="{Binding ElementName=lu1, Path=CanStream}">
                        <StackPanel Orientation="Horizontal">
                            <myControls:AutoGreyableImage Source="..\Resources\icon_potplayer.png" Margin="2"/>
                            <TextBlock Margin="2" VerticalAlignment="Center">Stream (PotPlayer)</TextBlock>
                        </StackPanel>
                    </Button>
                </StackPanel>
            </GroupBox>
        </Grid>




    </Grid>
</UserControl>
